package com.sdf.com.mvp_rx_retraft.utils;

import android.annotation.SuppressLint;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

    /**
     * yyyy-MM-dd HH:mm:ss
     *
     * @return
     */
    @SuppressLint("SimpleDateFormat")
    public static String getNowYMDHMSTime() {


        SimpleDateFormat mDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        String date = mDateFormat.format(new Date());
        return date;
    }

    /**
     * MM-dd HH:mm:ss
     *
     * @return
     */
    @SuppressLint("SimpleDateFormat")
    public static String getNowMDHMSTime() {

        SimpleDateFormat mDateFormat = new SimpleDateFormat(
                "MM-dd HH:mm:ss");
        String date = mDateFormat.format(new Date());
        return date;
    }

    /**
     * MM-dd
     *
     * @return
     */
    @SuppressLint("SimpleDateFormat")
    public static String getNowYMD() {

        SimpleDateFormat mDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd");
        String date = mDateFormat.format(new Date());
        return date;
    }

    /**
     * yyyy-MM-dd
     *
     * @param date
     * @return
     */
    @SuppressLint("SimpleDateFormat")
    public static String getYMD(Date date) {

        SimpleDateFormat mDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd");
        String dateS = mDateFormat.format(date);
        return dateS;
    }

    /**
     * 给定秒钟时间转成小时，分钟，秒
     *
     * @param secStr
     * @return
     */
    public static String durationTime(String secStr) {
        if (secStr != null && secStr != "") {
            try {
                int second = Integer.parseInt(secStr);
                int h = 0;
                int d = 0;
                int s = 0;
                int temp = second % 3600;
                if (second > 3600) {
                    h = second / 3600;
                    if (temp != 0) {
                        if (temp > 60) {
                            d = temp / 60;
                            if (temp % 60 != 0) {
                                s = temp % 60;
                            }
                        } else {
                            s = temp;
                        }
                    }
                } else {
                    d = second / 60;
                    if (second % 60 != 0) {
                        s = second % 60;
                    }
                }
                if (h == 0 && d != 0) {
                    return d + "分" + s + "秒";
                } else if (h == 0 && d == 0) {
                    return s + "秒";
                }
                return h + "时" + d + "分" + s + "秒";
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
        return "0秒";
    }
}


